<! DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>返回数组中指定元素的下标</title>
</head>
<body>
<script>
    function findall(a,x){
        var results=[];
        len=a.length;
        pos=0;
        while(pos<len){
            pos=a.indexOf(x,pos);
            if(pos ===-1){
                break;
            }
            results.push(pos);
            pos+=1;
        }
        return results;
    }
    var arr=['a','b','d','d','c','d','d'];
    document.write(findall(arr,'d'))
    function count(arr,item){
        var number=0;
        for(var i=0;i<arr.length;i++){
            if(arr[i]==item){
                number++;
            }
        }
        return number;
    }
    document.write('</br>'+count(arr,'d'));
</script>
</body>
</html